home *** CD-ROM | disk | FTP | other *** search
- // csystray.cpp : Implementation file for the CWin95SystemTray class.
- //
-
- #include "stdafx.h"
- #include "systray.h"
- #include "csystray.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- #define STF_AUTOUNREGISTER 0x00000001
-
-
- CWin95SystemTray::CWin95SystemTray(HWND hWnd,
- UINT uCallbackMsgID)
- {
- Init();
- Attach(hWnd);
- EnableAutoUnregister();
- }
-
- CWin95SystemTray::~CWin95SystemTray()
- {
- if ((m_dwFlags & STF_AUTOUNREGISTER) && (m_NotifyIconData.hWnd))
- {
- ItemDelete(m_NotifyIconData.uID);
- }
-
- Init();
- }
-
- BOOL CWin95SystemTray::Attach(HWND hWnd)
- {
- m_NotifyIconData.hWnd = hWnd;
- return(hWnd ? TRUE : FALSE);
- }
-
- void CWin95SystemTray::EnableAutoUnregister(BOOL bEnable)
- {
- if (bEnable)
- {
- m_dwFlags |= STF_AUTOUNREGISTER;
- }
- else
- {
- m_dwFlags &= ~(STF_AUTOUNREGISTER);
- }
- }
-
- void CWin95SystemTray::RegisterCallbackMessage(UINT uMsgID)
- {
- m_NotifyIconData.uCallbackMessage = uMsgID;
- }
-
- HWND CWin95SystemTray::Detach(HWND hWnd)
- {
- HWND hOldWnd = m_NotifyIconData.hWnd;
- m_NotifyIconData.hWnd = hWnd;
- return(hOldWnd);
- }
-
- BOOL CWin95SystemTray::ItemAdd(UINT uID)
- {
- return(SystemTrayMessage(m_NotifyIconData.hWnd, NIM_ADD,
- uID, NULL, NULL));
- }
-
- BOOL CWin95SystemTray::ItemDelete(UINT uID)
- {
- return(SystemTrayMessage(m_NotifyIconData.hWnd, NIM_DELETE,
- uID, NULL, NULL));
- }
-
- BOOL CWin95SystemTray::ItemModify(UINT uID,
- HICON hIcon,
- LPCSTR pszBubbleText)
- {
- return(SystemTrayMessage(m_NotifyIconData.hWnd, NIM_MODIFY,
- uID, hIcon, pszBubbleText));
- }
-
- BOOL CWin95SystemTray::ItemSetBubbleText(UINT uID,
- LPCSTR pszBubbleText)
- {
- return(ItemModify(uID, NULL, pszBubbleText));
- }
-
- void CWin95SystemTray::Init(void)
- {
- m_NotifyIconData.cbSize = sizeof(NOTIFYICONDATA);
- m_NotifyIconData.hWnd = NULL;
- m_NotifyIconData.uID = 0;
- m_NotifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
- m_NotifyIconData.uCallbackMessage = 0;
- m_NotifyIconData.hIcon = NULL;
- m_NotifyIconData.szTip[0] = '\0';
- m_dwFlags = 0;
- }
-
- BOOL CWin95SystemTray::SystemTrayMessage(HWND hWnd,
- DWORD dwMessage,
- UINT uID,
- HICON hIcon,
- LPCSTR pszBubbleText)
- {
- BOOL bRet;
-
- m_NotifyIconData.hWnd = hWnd;
- m_NotifyIconData.uID = uID;
- m_NotifyIconData.hIcon = hIcon;
-
- if (pszBubbleText != NULL)
- {
- lstrcpyn(m_NotifyIconData.szTip, pszBubbleText,
- sizeof(m_NotifyIconData.szTip));
- }
- else
- {
- m_NotifyIconData.szTip[0] = '\0';
- }
-
- bRet = Shell_NotifyIcon(dwMessage, &m_NotifyIconData);
- return(bRet);
- }
-